package com.wingscode.modules.common.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wingscode.common.utils.PageUtils;
import com.wingscode.common.utils.Query;
import com.wingscode.modules.common.dao.ChatDetailDao;
import com.wingscode.modules.common.entity.ChatDetailEntity;
import com.wingscode.modules.common.service.ChatDetailService;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("chatDetailService")
public class ChatDetailServiceImpl extends ServiceImpl<ChatDetailDao, ChatDetailEntity> implements ChatDetailService {

    @Override
    public void updateByFromAgent(ChatDetailEntity chatDetail) { this.baseMapper.updateByFromAgent(chatDetail); }

    @Override
    public void updateByToAgent(ChatDetailEntity chatDetail) { this.baseMapper.updateByToAgent(chatDetail); }

    @Override
    public void updateByToUserId(ChatDetailEntity chatDetail) { this.baseMapper.updateByToUserId(chatDetail); }

    @Override
    public PageUtils getDetail(Map<String, Object> params) {
        Integer chatId = null;
        if (params.containsKey("chatId"))
            chatId = Integer.parseInt(params.get("chatId").toString());

        IPage<ChatDetailEntity> page = this.baseMapper.getDetail(new Query<ChatDetailEntity>().getPage(params), chatId);

        return new PageUtils(page);
    }

    @Override
    public void deleteByChatId(Integer chatId) { this.baseMapper.deleteByChatId(chatId); }

}
